﻿using Demo.AttachFileService.Models;
using Demo.AttachFileService.Services;
using JT808.Protocol.Extensions.JTActiveSafety.MessageBody;
using JT808.Protocol.Extensions.JTActiveSafety.Metadata;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
 
namespace JTActiveSafety.Gateway
{
    public class SqliteAttachFileRecvService : IAttachFileRecvService
    {
        private readonly ILogger _logger;
        private readonly ISqliteDbService _dbService;

        public SqliteAttachFileRecvService(ILoggerFactory loggerFactory, ISqliteDbService fileSaveCache)
        {
            _logger = loggerFactory.CreateLogger<SqliteAttachFileRecvService>();
            _dbService = fileSaveCache;
        }

        public void CreateAlarmAttachFileInfo(string terminalPhoneNo, JT808_0x1210 input)
        {
            _dbService.CreateAlarmInfoAndAttachFiles(terminalPhoneNo,input);
        }

        public void AddFileReceiveRecord(JT808_0x1299 input)
        {
            _dbService.AddFileRecvRecored(input);
        }

        public CheckFileIntegrityResult CheckFileIntegrity(string fileName, out uint fileSize, out List<Node> missingNodes)
        {
           return _dbService.CheckFileIntegrity(fileName, out fileSize, out missingNodes, true);
        }
    }
}
